# -*- coding: utf-8 -*-
"""
Created on Sun Jun 24 17:57:46 2018

@author: Luther
"""

import tkinter as tk
from tkinter.filedialog import askdirectory, asksaveasfilename
import getSense
import os


class App(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.pack()
        self.createWidgets()

    def selectInputDirectory(self):
        inputDirectory = askdirectory()
        self.inputPathEntry.delete(0, 'end')
        self.inputPathEntry.insert(0, inputDirectory)

    def selectOutputFile(self):
        outputFile = asksaveasfilename()
        self.outputPathEntry.delete(0, 'end')
        self.outputPathEntry.insert(0, outputFile)

    def startCompte(self):
        path = self.inputPathEntry.get()
        ret_path = self.outputPathEntry.get()
        getSense.compute(path, ret_path)

    def openFile(self):
        ret_path = self.outputPathEntry.get()
        os.popen(ret_path)

    def createWidgets(self):
        self.inputPathLable = tk.Label(self, text='请输入待检索文件目录：')
        self.inputPathLable.pack()
        self.inputPathEntry = tk.Entry()
        self.inputPathButton = tk.Button(
            self, text='浏览', command=self.selectInputDirectory)
        self.inputPathButton.pack()
        self.inputPathEntry.pack(before=self.inputPathButton)
        self.outputPathLable = tk.Label(self, text='请输入输出文件位置：')
        self.outputPathLable.pack()
        self.outputPathEntry = tk.Entry()
        self.outputPathButton = tk.Button(
            self, text='浏览', command=self.selectOutputFile)
        self.outputPathButton.pack()
        self.outputPathEntry.pack(before=self.outputPathButton)
        self.startButton = tk.Button(
            self, text='开始计算', command=self.startCompte)
        self.startButton.pack()
        self.openFileButton = tk.Button(
            self, text='打开文件', command=self.openFile)
        self.openFileButton.pack()


if __name__ == "__main__":
    app = App()
    app.master.title("sim")
    app.mainloop()
